package com.ruoyi.base.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.base.domain.BasPollutionsource;
import com.ruoyi.base.mapper.BasPollutionsourceMapper;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.BusPsBasEquipmentMapper;
import com.ruoyi.base.domain.BusPsBasEquipment;
import com.ruoyi.base.service.IBusPsBasEquipmentService;

/**
 * 在线-设备Service业务层处理
 * 
 * @author maliang
 * @date 2025-09-22
 */
@Service
public class BusPsBasEquipmentServiceImpl implements IBusPsBasEquipmentService 
{
    @Autowired
    private BusPsBasEquipmentMapper busPsBasEquipmentMapper;
    @Autowired
    private BasPollutionsourceMapper basPollutionsourceMapper;

    /**
     * 查询在线-设备
     * 
     * @param datagathercode 在线-设备主键
     * @return 在线-设备
     */
    @Override
    public BusPsBasEquipment selectBusPsBasEquipmentByDatagathercode(String datagathercode)
    {
        return busPsBasEquipmentMapper.selectBusPsBasEquipmentByDatagathercode(datagathercode);
    }

    /**
     * 查询在线-设备列表
     * 
     * @param busPsBasEquipment 在线-设备
     * @return 在线-设备
     */
    @Override
    public List<BusPsBasEquipment> selectBusPsBasEquipmentList(BusPsBasEquipment busPsBasEquipment)
    {
        return busPsBasEquipmentMapper.selectBusPsBasEquipmentList(busPsBasEquipment);
    }

    /**
     * 新增在线-设备
     * 
     * @param busPsBasEquipment 在线-设备
     * @return 结果
     */
    @Override
    public int insertBusPsBasEquipment(BusPsBasEquipment busPsBasEquipment)
    {
        if(StringUtils.isNotEmpty(busPsBasEquipment.getPolluteid())){
            BasPollutionsource basPollutionsource = basPollutionsourceMapper.selectBasPollutionsourceById(busPsBasEquipment.getPolluteid());
            if(basPollutionsource == null){
                throw new ServiceException("企业信息不存在");
            }
            busPsBasEquipment.setEntcode(UUID.randomUUID().toString());
        }
        busPsBasEquipment.setUpdatedate(DateUtils.getNowDate());
        return busPsBasEquipmentMapper.insertBusPsBasEquipment(busPsBasEquipment);
    }

    /**
     * 修改在线-设备
     * 
     * @param busPsBasEquipment 在线-设备
     * @return 结果
     */
    @Override
    public int updateBusPsBasEquipment(BusPsBasEquipment busPsBasEquipment)
    {
        if(StringUtils.isNotEmpty(busPsBasEquipment.getPolluteid())){
            BasPollutionsource basPollutionsource = basPollutionsourceMapper.selectBasPollutionsourceById(busPsBasEquipment.getPolluteid());
            if(basPollutionsource == null){
                throw new ServiceException("企业信息不存在");
            }
        }
        busPsBasEquipment.setUpdatedate(DateUtils.getNowDate());
        return busPsBasEquipmentMapper.updateBusPsBasEquipment(busPsBasEquipment);
    }

    /**
     * 批量删除在线-设备
     * 
     * @param datagathercodes 需要删除的在线-设备主键
     * @return 结果
     */
    @Override
    public int deleteBusPsBasEquipmentByDatagathercodes(String[] datagathercodes)
    {
        return busPsBasEquipmentMapper.deleteBusPsBasEquipmentByDatagathercodes(datagathercodes);
    }

    /**
     * 删除在线-设备信息
     * 
     * @param datagathercode 在线-设备主键
     * @return 结果
     */
    @Override
    public int deleteBusPsBasEquipmentByDatagathercode(String datagathercode)
    {
        return busPsBasEquipmentMapper.deleteBusPsBasEquipmentByDatagathercode(datagathercode);
    }
}
